perm filename MANFIG.MF[MF,DEK] blob sn#492162 filedate 1980-01-25 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00035 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00004 00002	% Figures for the METAFONT manual
C00006 00003	"Fig. 1-1. Six points"
C00007 00004	"Fig. 1-2. Six points and one line"
C00008 00005	"Fig. 1-3. Six points and three lines"
C00009 00006	"Fig. 2-1. Six points and a bean shape"
C00010 00007	"Fig. 2-2. Six points and an ugly line"
C00011 00008	"Fig. 2-3. METAFONT curves when theta=60 and phi≥0."
C00012 00009	"Fig. 2-4. METAFONT curves when theta=60 and phi<0."
C00013 00010	"Fig. 2-5. Heart points"
C00014 00011	"Fig. 2-6. Lumpy heart"
C00015 00012	"Fig. 2-7. Better heart"
C00016 00013	"Fig. 2-8. Ten-point heart"
C00017 00014	"Fig. 2-9. True valentine"
C00018 00015	"Fig. 2-10. Four-point valentine"
C00019 00016	"Fig. 2-11. Shoe points"
C00020 00017	"Fig. 2-12a. Gnarled shoe"
C00021 00018	"Fig. 2-12b. True shoe"
C00022 00019	"Fig. 3-1. cpen, hpen, vpen"
C00023 00020	"Fig. 3-2a. True shoe with hpen"
C00024 00021	"Fig. 3-2b. True valentine with vpen"
C00025 00022	"Fig. 3-3. cpen, lpen#, rpen#"
C00026 00023	"Fig. 3-4. True valentine with spen"
C00027 00024	"Fig. 3-5. Example of epen"
C00028 00025	% Fig. 4-1 will be typeset
C00029 00026	% Fig. 4-2 will be typeset
C00030 00027	"Fig. 5-1. Intersection of straight lines"
C00031 00028	"Fig. 6-1. Filled valentine"
C00032 00029	"Fig. 6-2. Crossed ddraw"
C00033 00030	"Fig. 7-1. Differences in rounding"
C00034 00031	"Fig. 8-1. Double use of darc"
C00035 00032	"Fig. 8-2. Superellipse"
C00036 00033	% preparation for Appendix E figures
C00043 00034	"Fig. E-1. The letter A"
C00044 00035	"The letter B"
C00045 ENDMK
C⊗;
% Figures for the METAFONT manual
proofmode; chardisplay; titletrace;

subroutine curve(var theta)(var phi)(index i,index j):
cpen; 1 draw i{cosd theta, sind theta}..j{cosd phi, -sind phi}.

subroutine arc(var s):
no proofmode; hpen;
x1=s+10; y1=50; x2=s; y2=0; x3=s+10; y3=-50;
9 draw 1{-1,-1}..2{0,-1}..3{+1,-1}.

subroutine darc(index i,index j,var maxwidth):
x1=x5=xi; x2=x4=1/sqrttwo[xi,xj]; x3=xj;
y1=yi; y5=yj; y3=1/2[yi,yj];
y2=1/sqrttwo[y3,yi]; y4=1/sqrttwo[y3,yj];
invisible x4-1,y4; invisible x2-1,y2;
hpen; draw |w0|1{x3-x1,0}..|2/3[w0,maxwidth]|2{x3-x1,y3-y1}..
    |maxwidth#|3{0,y3-y1}..|2/3[w0,maxwidth]|
    4{x5-x3,y5-y3}..|w0|5{x5-x3,0}.
"Fig. 1-1. Six points";
no proofmode; x8=-10;y8=110; x9=210;y9=-10; epen (0,0)#;
1 draw 8; draw 9; proofmode; % This makes raster visible without a subsequent draw;
x1=x4=y4=y5=y6=0;
x2=x5=y1=y2=y3=100;
x3=x6=200.
"Fig. 1-2. Six points and one line";
x1=x4=y4=y5=y6=0;
x2=x5=y1=y2=y3=100;
x3=x6=200;
cpen; 9 draw 1..6.
"Fig. 1-3. Six points and three lines";
x1=x4=y4=y5=y6=0;
x2=x5=y1=y2=y3=100;
x3=x6=200;
cpen; 9 draw 1..6; draw 2..5; draw 3..4.
"Fig. 2-1. Six points and a bean shape";
x1=x4=y4=y5=y6=0;
x2=x5=y1=y2=y3=100;
x3=x6=200;
cpen; 9 draw 5..4..1..3..6..5.
"Fig. 2-2. Six points and an ugly line";
x1=x4=y4=y5=y6=0;
x2=x5=y1=y2=y3=100;
x3=x6=200;
cpen; 9 draw 4..1..3.
"Fig. 2-3. METAFONT curves when theta=60 and phi≥0.";
x1=y1=y2=0; x2=150;
invisible x1,y1+1; invisible x2,y2+1;
call curve(60,120,1,2);
call curve(60,90,1,2);
call curve(60,60,1,2);
call curve(60,30,1,2);
call curve(60,0,1,2).
"Fig. 2-4. METAFONT curves when theta=60 and phi<0.";
x1=y1=y2=0; x2=150;
call curve(60,-120,1,2);
call curve(60,-90,1,2);
call curve(60,-60,1,2);
call curve(60,-30,1,2).
"Fig. 2-5. Heart points";
no proofmode; x9=-10;y9=200; x10=210;y10=-10; epen (0,0)#;
draw 9; draw 10; proofmode; % This makes raster visible without a subsequent draw;
x1=100; y1=162;
x2=200-x8=140; y2=y8=178;
x3=200-x7=185; y3=y7=125;
x4=200-x6=161; y4=y6=57;
x5=100; y5=0.
"Fig. 2-6. Lumpy heart";
x1=100; y1=162;
x2=200-x8=140; y2=y8=178;
x3=200-x7=185; y3=y7=125;
x4=200-x6=161; y4=y6=57;
x5=100; y5=0;
cpen; 9 draw 1..2..3..4..5; draw 5..6..7..8..1.
"Fig. 2-7. Better heart";
x1=100; y1=162;
x2=200-x8=140; y2=y8=178;
x3=200-x7=185; y3=y7=125;
x4=200-x6=161; y4=y6=57;
x5=100; y5=0;
cpen; 9 draw 1{50,40}..2..3..4..5{-50,-36};
draw 5{-50,36}..6..7..8..1{50,-40}.
"Fig. 2-8. Ten-point heart";
x1=100; y1=162;
x2=200-x8=140; y2=y8=178;
x3=200-x7=185; y3=y7=125;
x4=200-x6=161; y4=y6=57;
x5=100; y5=0;
x9=200-x10=181; y9=y10=97;
cpen; 9 draw 1{50,40}..2..3..9..4..5{-50,-36};
draw 1{-50,40}..8..7..10..6..5{50,-36}.
"Fig. 2-9. True valentine";
x1=100; y1=162;
x2=200-x8=140; y2=y8=178;
x3=200-x7=185; y3=y7=125;
x4=200-x6=161; y4=y6=57;
x5=100; y5=0;
cpen; 9 draw 1{50,40}..2{1,0}..3{0,-1}..4..5{-50,-36};
draw 1{-50,40}..8{-1,0}..7{0,-1}..6..5{50,-36}.
"Fig. 2-10. Four-point valentine";
x1=100; y1=162;
x2=200-x8=140; y2=y8=178;
x3=200-x7=185; y3=y7=125;
x4=200-x6=161; y4=y6=57;
x5=100; y5=0;
cpen; 9 draw 1{50,40}..3{0,-1}..5{-50,-36};
draw 1{-50,40}..7{0,-1}..5{50,-36}.
"Fig. 2-11. Shoe points";
incy -25;
no proofmode; x10=-10;y10=325; x11=210;y11=-10; epen (0,0)#;
draw 11; draw 10; proofmode; % This makes raster visible without a subsequent draw;
x1=77;y1=322;x2=132;y2=220;x3=117;y3=150;
x4=120;y4=100;x5=131;y5=55;x6=95;y6=2;
x7=48;y7=60;x8=38;y8=140;x9=20;y9=200;
incy 0.
"Fig. 2-12a. Gnarled shoe";
incy -25;
x1=77;y1=322;x2=132;y2=220;x3=117;y3=150;
x4=120;y4=100;x5=131;y5=55;x6=95;y6=2;
x7=48;y7=60;x8=38;y8=140;x9=20;y9=200;
cpen; 9 draw (9..)1..2..3..4..5..6..7..8..9..1(..2);
incy 0.
"Fig. 2-12b. True shoe";
incy -25;
x1=77;y1=322;x2=132;y2=220;x3=117;y3=150;
x4=120;y4=100;x5=131;y5=55;x6=95;y6=2;
x7=48;y7=60;x8=38;y8=140;x9=20;y9=200;
x10=125;y10=184;
cpen; 9 draw1{1,0}..2{0,-1}..10{-25,-60}..3{0,-1}..4{18,-60}
	..5{0,-1}..6{-1,0}..7{0,1}..8{-30,60}..9{0,1}..1{1,0};
incy 0.
"Fig. 3-1. cpen, hpen, vpen";
x1=0;x2=100;x3=200;y1=y2=y3=0;
hpenht 25; vpenwd 25;
cpen; 75 draw 1;
hpen; 75 draw 2;
vpen; 75 draw 3.
"Fig. 3-2a. True shoe with hpen";
no proofmode;
incy -25;
x1=77;y1=322;x2=132;y2=220;x3=117;y3=150;
x4=120;y4=100;x5=131;y5=55;x6=95;y6=2;
x7=48;y7=60;x8=38;y8=140;x9=20;y9=200;
x10=125;y10=184;
proofmode;
hpenht 3;
hpen; 9 draw1{1,0}..2{0,-1}..10{-25,-60}..3{0,-1}..4{18,-60}
	..5{0,-1}..6{-1,0}..7{0,1}..8{-30,60}..9{0,1}..1{1,0};
incy 0.
"Fig. 3-2b. True valentine with vpen";
no proofmode;
x1=100; y1=162;
x2=200-x8=140; y2=y8=178;
x3=200-x7=185; y3=y7=125;
x4=200-x6=161; y4=y6=57;
x5=100; y5=0;
proofmode;
vpenwd 3;
vpen; 9 draw 1{50,40}..2{1,0}..3{0,-1}..4..5{-50,-36};
draw 1{-50,40}..8{-1,0}..7{0,-1}..6..5{50,-36}.
"Fig. 3-3. cpen, lpen#, rpen#";
x1=0;x2=50;x3=100;y1=y2=y3=0;
invisible x1+1,y1; invisible x3-1,y3;
lpenht 25; rpenht 25;
cpen; 150 draw 2;
lpen#; 35 draw 3;
rpen#; 35 draw 1.
"Fig. 3-4. True valentine with spen";
no proofmode;
x1=100; y1=162;
x2=200-x8=140; y2=y8=178;
x3=200-x7=185; y3=y7=125;
x4=200-x6=161; y4=y6=57;
x5=100; y5=0;
proofmode;
spen(4/27,-16/81 sqrt 3,28/81,0,0,0,0);
draw 1{50,40}..2{1,0}..3{0,-1}..4..5{-50,-36};
draw 1{-50,40}..8{-1,0}..7{0,-1}..6..5{50,-36}.
"Fig. 3-5. Example of epen";
x1=0;y1=-20;x2=50;y2=0;x3=100;y3=20;
invisible x1,y1+1; invisible x2,y2+1; invisible x3,y3+1;
cpen;150 draw2;
epen(0,0)(-1,1)(-2,2)(-3,3)(-4,4)#;
draw1..3.
% Fig. 4-1 will be typeset
% Fig. 4-2 will be typeset
"Fig. 5-1. Intersection of straight lines";
x1=y1=0; x2=y2=100;
x3=25; y3=75;
x4=200; y4=50;
x5=alpha[x1,x2]=beta[x3,x4];
y5=alpha[y1,y2]=beta[y3,y4];
cpen; 9 draw 1..2; draw 3..4.
"Fig. 6-1. Filled valentine";
no proofmode;
x1=100; y1=162;
x2=200-x8=140; y2=y8=178;
x3=200-x7=185; y3=y7=125;
x4=200-x6=161; y4=y6=57;
x5=100; y5=0;
x9=1/3[x1,x3]; y9=1/3[y1,y5];
proofmode;
epen (0,0); 9 ddraw 1{50,40}..2{1,0}..3{0,-1}..4..5{-50,-36},
	9..9..9..9..9;
ddraw 1{-50,40}..8{-1,0}..7{0,-1}..6..5{50,-36}, 9..9..9..9..9.
"Fig. 6-2. Crossed ddraw";
x1=5;y1=10;x2=300;y2=-5;
x3=0;y3=0;x4=298;y4=10;
cpen; 9 ddraw 1{x2-x1,2(y2-y1)}..2{1,0},
	3{1,0}..4{x4-x3,2(y4-y3)}.
"Fig. 7-1. Differences in rounding";
hpenht 3; call arc(0); call arc(50.4999); call arc(100.5001).
"Fig. 8-1. Double use of darc";
new w0; hpenht 3;
x1=0; y1=y3=150; x2=50; y2=0; x3=100;
sqrttwo=sqrt 2; w0=3; w1=9;
call `a darc(2,1,w1);
call `b darc(2,3,w1).
"Fig. 8-2. Superellipse";
new sqrttwo;
x1=0; y1=y3=150; x2=50; y2=0; x3=100;
sqrttwo=1.319507911; % 2↑(2/5), a la Piet Hein;
call `a darc(2,1,w1);
call `b darc(2,3,w1).
% preparation for Appendix E figures
eps=.000314159;	% a very small random positive number
new pixels; pixels=36; blacker=0.
new sqrttwo,w0,w1,w2,w3,w4,w5,w6,w7,w8;

subroutine fontbegin:	% Initialize before making a font:
no eqtrace;	% Turn off tracing within this subroutine.
new typesize;	% the vertical size of the font
new cf;	% conversion factor, approximately equal to pixels
new h,d,c,e,o,b,s,a;	% raster-oriented vertical dimensions
w0=round(pixels.pw+blacker);
w1=round(pixels.pwi+blacker);
w2=round(pixels.pwii+blacker);
w3=round(pixels.pwiii+blacker);
w4=round(pixels.pwiv+blacker);
w5=round(pixels.pwv+blacker);
w6=round(pixels.pw/aspect+blacker);
w7=round(pixels.pwi/aspect+blacker);
w8=round(pixels.pwiv/aspect+blacker);
hpenht w6;  vpenwd w0;
typesize=ph+pd+2pb; cf.typesize=pixels.typesize-1;
h=round cf.ph;  d=round cf.pd; 
c=round cf.px;
o=round cf.po;  s=cf.ps; 
a=.5 round 2cf.pa;
b=-round(.5(h+d-typesize.pixels));
hpen; e=good0 cf.pe;
maxht h+b;
trxy slant;
fi.

subroutine charbegin(var charno)	%seven-bit character code
		(var charuw)		%character width in units
	(var lftcorr, var rtcorr)	%serif-oriented corrections in units
(var charh, var chard, var chari):	%charht, chardp, charic values in points
no eqtrace; no calltrace;	% Shut off tracing in this subroutine.
new uw;	% the correct character width in units
new r;	% raster-oriented character width
new u;	% raster-oriented design unit
new tu;	% unmodified raster-oriented unit
new italcorr;	% italic correction
if chari≥0: italcorr=chari; else: italcorr=0;
fi;
charcode charno; charht charh; chardp chard; charic italcorr;
tu=pu.pixels;
if fixwidth=0: r+2=round charuw.tu; uw=charuw-sc.(lftcorr+rtcorr);
else: r+2=round((9+sc.(lftcorr+rtcorr)).tu); uw=9;
fi;
u.charuw=r;
charwd uw.pu; chardw uw.tu;
incx round(-sc.lftcorr.tu);
call box(round sc.lftcorr.tu);
fi.

subroutine box(var offset):	% Draw guildelines and box around a character:
no drawtrace; no proofmode;
new topp,bott,left,right,pos;
topp=h+b; bott=-d-b;
left=offset; right=offset+u.uw;
x1=x3=x5=x7=x9=x11=x13=x15=x17=left;
x2=x4=x6=x8=x10=x12=x14=x16=x18=right;
y1=y2=0; cpen;  1 draw1..2;	% baseline
y3=y4=e; draw3..4;	% e-height
y5=y6=c; draw5..6;	% x-height
y7=y8=h; draw7..8;	% h-height
y9=y10=topp; draw9..10;	% top of character
y11=y12=-d; draw11..12;	% descender line
y13=y14=bott; draw13..14;	% bottom of character
trxy 0;	% Temporarily turn off the slant.
y15=y16=topp;  y17=y18=bott;
draw15..17; draw16..18;	% left and right edges
if italcorr>0: x19=x20=right+italcorr.pixels;
	y19=topp;  y20=0; draw19..20;	% show italic correction
fi;
trxy slant;	% Restore slanted transformation
pos=0; call unitlines.	% Draw the unit guidelines.

subroutine unitlines:	% Recursive subroutine to draw guidelines:
x1=x2=pos;y1=topp;y2=bott;cpen;
if pos≥left: 1 draw1..2;
fi;
new pos; pos=x1+u; if pos≤right: call unitlines; fi.
subroutine serif(index i)	%point where serif appears
		(index k)	%w-variable for stem line
		(index j)	%another point on the stem line
		(var sl):	%serif length
y1=yi;
if yi<yj: y2=yi+s;  else: y2=yi-s;
fi;
hpen;
if sl<0: lft0x1=lft k xi+sl.u-eps;
	lft0x2=lft k (y2-yi)/(yj-yi)[xi,xj];
else: rt0x1=rt k xi+sl.u+eps;
	rt0x2=rt k (y2-yi)/(yj-yi)[xi,xj];
fi;
no proofmode;
x3=1/3[x1-sl.u,1/2[x1,x2]]; 
y3=1/3[yi,1/2[y1,y2]];
minvr 0; minvs 0;
w0 ddraw 1{xi-x1,0}..3..2{xj-xi,yj-yi}, 1..1..i;
minvr 0.5; minvs 0.5.

subroutine darc(index i)	%starting point
		(index j)	%opposite corner point
		(var maxwidth):	%the pen grows from w0 to this size
x5=xi;  x2=x4=1/sqrttwo [xi,xj];  x3=xj;
y5=yj;  y3=1/2[yi,yj];
y2=1/sqrttwo [y3,yi];  y4=1/sqrttwo [y3,yj];
hpen;  draw |w0|i{x3-xi,0}..|2/3[w0,maxwidth]|2{x3-xi,y3-yi}..
	|maxwidth#|3{0,y3-yi}..
	|2/3[w0,maxwidth]|4{x5-x3,y5-y3}..|w0|5{x5-x3,0}.

ph=250/36; px=160/36; pe=90/36; pd=70/36;
pb=20/36; po=4/36; ps=20/36; pa=.5(ph-pd);
pw=9/36; pwi=27/36; pwii=32/36; pwiii=36/36;
pwiv=32/36; pwv=38/36; aspect=1.0;
pu=20/36; lcs=1.075; ucs=1.7; sc=0;
slant=0; sqrttwo=sqrt 2; fixwidth=0;
halfd=0; varg=0.
"Fig. E-1. The letter A";
call fontbegin;
call charbegin(`A,13,2,2,ph,0,0);
hpen;
lft0x1=round 1.5u; bot0y1=0;
rt5x4=round(r-1.5u); bot5y4=0;
top0y3=top5y2=h+o;
x3-x1=x4-x2; rt5x2=rt0x3;
w5 draw2..4;	% right diagonal stroke
y5=y6=e;
x5-1=(y5-y1)/(y3-y1)[x1,x3];
x6+1=(y6-y4)/(y2-y4)[x4,x2];
w0 draw 5..6;	% bar line
lpen#; w5 draw3..5;	% erase excess at upper left
hpen; w0 draw3..1;	% left diagonal stroke
if ucs≠0:
	call `a serif(1,0,3,-.5ucs);
	call `b serif(1,0,3,+ucs);	% left serifs
	call `c serif(4,5,2,-ucs);
	call `d serif(4,5,2,+.5ucs);	% right serifs
fi.
"The letter B";
call charbegin(`B,12,2,0,ph,0,ph.slant-2pu);
hpen;
lft4x1=lft4x2=round 2u; top4y1=h; 
bot4y2=0;
w4 draw1..2;	% stem
if ucs≠0:
	call `a serif(1,4,2,-ucs);
	call `b serif(1,4,2,.5ucs);	% upper serif
	call `c serif(2,4,1,-ucs);
	call `d serif(2,4,1,.5ucs);	% lower serif
fi;
x3=1/2[2u,r];  y3=y1;
rt5x4=round(r-u);  y4=good0 1/2h;
w0 draw 1..3;	% upper bar line
call `e darc(3,4,w5);	% upper counter
x5=x1; x6=x3+1/2u;  y4=y5=y6;
rt5x7=round(r-1/2u); bot5y7=0;
w0 draw 5..6;	% middle bar line
call `f darc(6,7,w5);	% lower counter
x8=x6;  y8=y7;  w0 draw2..8.	% lower bar line